package com.guangjian.common.sql;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;

public class SqlFileLoader extends HashMap<String, String> {
	private static final long serialVersionUID = -4562333882477965611L;

	public void load(InputStream iStream) throws IOException, SAXException {
		if (iStream == null) {
			return;
		}

		XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");

		DefaultHandler handler = new SqlXMLHandler(this);

		reader.setContentHandler(handler);
		reader.setErrorHandler(handler);

		InputSource source = new InputSource(iStream);
		reader.parse(source);
	}
}
